//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  http://www.nopCommerce.com/License.aspx. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations under the License.
// 
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using Tathata.Common.Caching;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;
using System.Globalization;
using Tathata.Common.DAL;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.EntityCollections;
using Tathata.Common.BLL.Managers;
using Tathata.Common.DAL.Managers;

namespace Tathata.Common.BLL.Managers
{
    /// <summary>
    /// Product specification attribute mapping manager
    /// </summary>
    public class ProductSpecificationAttributeManager
    {
        #region Constants
        private const string PRODUCTSPECIFICATIONATTRIBUTE_ALLBYPRODUCTID_KEY = "Nop.productspecificationattribute.allbyproductid-{0}";
        #endregion

        #region Methods
        /// <summary>
        /// Deletes a product specification attribute mapping
        /// </summary>
        /// <param name="ProductSpecificationAttributeID">Product specification attribute identifier</param>
        public static void DeleteProductSpecificationAttribute(int ProductSpecificationAttributeID)
        {
            ProductSpecificationAttributeDBManager.DeleteProductSpecificationAttribute(ProductSpecificationAttributeID);

            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(PRODUCTSPECIFICATIONATTRIBUTE_ALLBYPRODUCTID_KEY);
            }
        }

        /// <summary>
        /// Gets a product specification attribute mapping collection
        /// </summary>
        /// <param name="ProductID">Product identifier</param>
        /// <returns>Product specification attribute mapping collection</returns>
        public static ProductSpecificationAttributeCollection GetProductSpecificationAttributesByProductID(int ProductID)
        {
            string key = string.Format(PRODUCTSPECIFICATIONATTRIBUTE_ALLBYPRODUCTID_KEY, ProductID);
            object obj2 = NopCache.Get(key);
            if (NopContext.IsCachable && (obj2 != null))
            {
                return (ProductSpecificationAttributeCollection)obj2;
            }

            ProductSpecificationAttributeCollection productSpecificationAttributes = ProductSpecificationAttributeDBManager.GetProductSpecificationAttributesByProductID(ProductID);

            if (NopContext.IsCachable)
            {
                NopCache.Max(key, productSpecificationAttributes);
            }
            return productSpecificationAttributes;
        }

        /// <summary>
        /// Gets a product specification attribute mapping 
        /// </summary>
        /// <param name="ProductSpecificationAttributeID">Product specification attribute mapping identifier</param>
        /// <returns>Product specification attribute mapping</returns>
        public static ProductSpecificationAttribute GetByProductSpecificationAttributeID(int ProductSpecificationAttributeID)
        {
            ProductSpecificationAttribute productSpecificationAttribute = ProductSpecificationAttributeDBManager.GetByProductSpecificationAttributeID(ProductSpecificationAttributeID);
            return productSpecificationAttribute;
        }

        /// <summary>
        /// Inserts a product specification attribute mapping
        /// </summary>
        /// <param name="ProductID">Product identifier</param>
        /// <param name="SpecificationAttributeID">Specification attribute identifier</param>
        /// <param name="AttributeValue">An attribute value</param>
        /// <param name="DisplayOrder">The display order</param>
        /// <returns>Product specification attribute mapping</returns>
        public static ProductSpecificationAttribute InsertProductSpecificationAttribute(int ProductID, int SpecificationAttributeID,
           string AttributeValue, int DisplayOrder)
        {
            ProductSpecificationAttribute productSpecificationAttribute = ProductSpecificationAttributeDBManager.InsertProductSpecificationAttribute(ProductID,
                SpecificationAttributeID, AttributeValue, DisplayOrder);
            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(PRODUCTSPECIFICATIONATTRIBUTE_ALLBYPRODUCTID_KEY);
            }
            return productSpecificationAttribute;
        }

        /// <summary>
        /// Updates the product specification attribute mapping
        /// </summary>
        /// <param name="ProductSpecificationAttributeID">product specification attribute mapping identifier</param>
        /// <param name="ProductID">Product identifier</param>
        /// <param name="SpecificationAttributeID">Specification attribute identifier</param>
        /// <param name="AttributeValue">An attribute value</param>
        /// <param name="DisplayOrder">The display order</param>
        /// <returns>Product specification attribute mapping</returns>
        public static ProductSpecificationAttribute UpdateProductSpecificationAttribute(int ProductSpecificationAttributeID, 
            int ProductID, int SpecificationAttributeID, string AttributeValue, int DisplayOrder)
        {
            ProductSpecificationAttribute productSpecificationAttribute = ProductSpecificationAttributeDBManager.UpdateProductSpecificationAttribute(ProductSpecificationAttributeID,
                ProductID, SpecificationAttributeID, AttributeValue, DisplayOrder);
            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(PRODUCTSPECIFICATIONATTRIBUTE_ALLBYPRODUCTID_KEY);
            }
            return productSpecificationAttribute;
        }
        #endregion
    }
}
